package utils;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Scanner;

public class FileUtil {
    public static void createInput(int size, String path) {
        for (int i = 1; i <= size; i++) {
            String fileName = path + "\\" + i + ".txt";
            File file = new File(fileName);
            if (!file.exists()) {
                try {
                    file.createNewFile();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            } else {
                System.out.println("文件 " + i + ".txt 已存在");
            }
        }
        System.out.println("文件创建完成!");
    }

    public static void createJava(String nameListPath, String targetPath)
            throws FileNotFoundException {
        Scanner in = new Scanner(new File(nameListPath));
        int k = 0;
        while (in.hasNext()) {
            String name = in.nextLine();
            k++;
            String filePath = targetPath + "\\HJ" + k + "_" + name + ".java";
            File file = new File(filePath);
            if (!file.exists()) {
                try {
                    file.createNewFile();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            } else {
                System.out.println("文件" + "HJ" + k + "_" + name + ".java" + "已存在");
            }
        }
        System.out.println("文件创建完成！");
    }

    public static void main(String[] args) throws FileNotFoundException {
        String nameListPath = "D:\\Projects\\JavaLearn\\src\\main\\java\\utils\\创建文件.txt";
        String targetPath = "D:\\Projects\\JavaLearn\\src\\main\\java\\华为OD机试B卷复用题\\进阶题";
        FileUtil.createJava(nameListPath, targetPath);
    }
}
